const express = require('express');
const router = express.Router();

// 接口1: 获取分支列表
router.get('/escm/project/nebs/depot/nebs_web/git/list_branches', (req, res) => {
    // 固定前两个分支
    const branches = [
        {
            name: "feature-BoCom12345678",
            sha: "ec3fa38d"
        },
        {
            name: "feature-BoCom12345678-daifa",
            sha: "ec3fa38d"
        }
    ];
    
    // 生成剩余98个分支
    for (let i = 0; i < 98; i++) {
        // 生成8位随机字符串
        const randomStr = Math.random().toString(36).substring(2, 10);
        branches.push({
            name: `feature-BoCom${randomStr}`,
            sha: "ec3fa38d"
        });
    }
    
    res.json({
        code: 0,
        data: branches
    });
});

// 接口2: 检查是否可以合并
router.get('/escm/project/nebs/depot/nebs_web/git/can_merge', (req, res) => {
    const { source, target } = req.query;
    
    if (!source || !target) {
        return res.status(400).json({
            code: -1,
            message: "source and target parameters are required"
        });
    }
    
    // 随机返回两种状态之一
    const statuses = ["ALREADY_MERGED", "MERGEABLE"];
    const randomStatus = statuses[Math.floor(Math.random() * statuses.length)];
    
    res.json({
        code: 0,
        data: {
            merge_status: randomStatus
        }
    });
});

module.exports = router;